package com.zmzncs.shop.module.shop.service.impl;

import org.springframework.beans.BeanUtils;
import com.zmzncs.shop.module.shop.pojo.managershop.*;
import com.zmzncs.shop.module.shop.mapper.ManagerShopMapper;
import com.zmzncs.shop.module.shop.service.ManagerShopService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 高博文
 * @since 2021-05-25
 */
@Service
public class ManagerShopServiceImpl extends ServiceImpl<ManagerShopMapper, ManagerShop> implements ManagerShopService {

    @Autowired
    private ManagerShopMapper managerShopMapper;

    /**
    * 分页
    */
    @Override
    public IPage<ManagerShopDTO> page(ManagerShopSearchForm form){
        IPage<ManagerShopDTO> iPage = managerShopMapper.list(form.getPage());

        return iPage;
    }

    /**
    * 添加
    */
    @Override
    @Transactional
    public void add(ManagerShopAddForm form){
        ManagerShop managerShop = new ManagerShop();
        BeanUtils.copyProperties(form, managerShop);

        managerShopMapper.insert(managerShop);
    }

    /**
    * 删除
    */
    @Override
    @Transactional
    public void delete(Long id){
        ManagerShop managerShop = new ManagerShop();
        managerShop.setId(id);
        managerShop.setIsDeleted(1);

        managerShopMapper.updateById(managerShop);
    }

    /**
    * 修改
    */
    @Override
    @Transactional
    public void update(ManagerShopUpdateForm form){
        ManagerShop managerShop = new ManagerShop();
        BeanUtils.copyProperties(form, managerShop);

        managerShopMapper.updateById(managerShop);
    }

    /**
    * 详情
    */
    @Override
    public ManagerShopDTO getById(Long id){
        ManagerShopDTO managerShopDTO = managerShopMapper.getById(id);

        return managerShopDTO;
    }

}
